package u.hnx.admin.system.controller;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import u.hnx.admin.captcha.config.CaptchaConfig;
import u.hnx.admin.security.api.HttpStatusAPI;
import u.hnx.admin.system.service.SysConfigService;

import java.util.HashMap;
import java.util.Map;

/*
创建人： 倔强的头发
创建时间：2024/6/26
功能描述:

*/
@RestController
@RequiredArgsConstructor
public class SysController  implements HttpStatusAPI {
    private final CaptchaConfig captcherConfig;
    private final SysConfigService configService;

    @GetMapping("/captcha")
    public Map<String, Object> captcha(HttpServletRequest request, HttpServletResponse response) {
        Map<String,Object> json = new HashMap<>();
        json.put(CODE_TAG,DEFAULT_HTTP_SUCCESS_CODE);
        json.put(MSG_TAG,DEFAULT_HTTP_SUCCESS_MSG);
        boolean captchaEnabled = configService.selectCaptchaEnabled();
        json.put("captchaEnabled", captchaEnabled);
        if (!captchaEnabled)
        {
            return json;
        }
        return captcherConfig.createCode(request, response,json);

    }
}
